JBoss Community Archive (Read Only)

RHQ

Adding alert definitions using the remote API

This feature is planned for the next release of RHQ (4.13)

Creating empty alert definition

The following snippet will create an alert definition to resource 11293 with the name "empty alertDefinition". No other parameters are necessary to create one. Rest of the necessary values are filled with the same defaults as when used from the GUI.

rhqadmin@localhost:7080$ var emptyAlertDef = new AlertDefinitionTemplate(11293, "empty alertDefinition")

rhqadmin@localhost:7080$ AlertDefinitionManager.createAlertDefinitionFromTemplate(emptyAlertDef)
AlertDefinition:
	      alertDampening: org.rhq.core.domain.alert.AlertDampening[ category=NONE[] ]
	alertDampeningEvents: []
	  alertNotifications: []
	              alerts: []
	 conditionExpression: ANY
	          conditions: []
	             context: Resource
	     controlFiltered: false
	               ctime: 1413886868935
	             deleted: false
	         description:
	             enabled: true
	               group:
	groupAlertDefinition:
	                  id: 10121
	               mtime: 1413886868935
	                name: empty alertDefinition
	      notifyFiltered: false
	            parentId: 0
	            priority: Medium
	            readOnly: false
	          recoveryId: 0
	            resource: Resource[id=11293, uuid=null, type=<null>, key=null, name=null, parent=<null>]
	       resourceGroup:
	        resourceType:
	         willRecover: false

rhqadmin@localhost:7080$

Changing parameters

Pressing tabulator to auto-complete the emptyAlertDef will print the available functions.

rhqadmin@localhost:7080$ emptyAlertDef.

addCondition       addNotification    alertDefinition    alertProtocol      conditions         dampening          description        disableWhenFired   enabled
name               priority           recoverAlert       resourceId
rhqadmin@localhost:7080$ emptyAlertDef.

function

parameters

description

addCondition

AbstractCondition

Add new conditions that will trigger the alert

addNotification

AlertNotificationTemplate

Add new alert notification rule

alertProtocol

BooleanExpression

Match ALL or ANY of the conditions to fire an alert

dampening

AlertDampeningTemplate

Sets the dampening rules

description

String

Gives the alert definition a description

enabled

boolean

Disables or enables this alert definition (default is true)

name

String

Changes the name of the alert definition

priority

AlertPriority

Set the alerting priority (default is MEDIUM)

disableWhenFired

boolean

Disables the alert definition when it fires

recoverAlert

Integer

Enables alertDefinition that has been disabled

Setting dampening rules

Dampening rules can be accessed by creating new AlertDampeningTemplate() and then inserting that to AlertDefinitionTemplate() using dampening(AlertDampeningTemplate) command.

rhqadmin@localhost:7080$ var dampeningRules = new AlertDampeningTemplate()

rhqadmin@localhost:7080$ dampeningRules.

category     occurences   period       time
rhqadmin@localhost:7080$ dampeningRules.category(Category.

Category.CONSECUTIVE_COUNT   Category.DURATION_COUNT      Category.INVERSE_COUNT       Category.NONE                Category.NO_DUPLICATES       Category.ONCE
Category.PARTIAL_COUNT
rhqadmin@localhost:7080$ dampeningRules.category(AlertDampening.Category.DURATION_COUNT)
AlertDampeningTemplate:

rhqadmin@localhost:7080$ dampeningRules.occurences(2)
AlertDampeningTemplate:

rhqadmin@localhost:7080$ dampeningRules.period(3)
AlertDampeningTemplate:

rhqadmin@localhost:7080$ dampeningRules.time(TimeUnits.

TimeUnits.DAYS      TimeUnits.HOURS     TimeUnits.MINUTES   TimeUnits.WEEKS
rhqadmin@localhost:7080$ dampeningRules.time(AlertDampening.TimeUnits.MINUTES)
AlertDampeningTemplate:

rhqadmin@localhost:7080$ dampeningRules.time(AlertDampening.TimeUnits.MINUTES)
rhqadmin@localhost:7080$ emptyAlertDef.dampening(dampeningRules)
AlertDefinitionTemplate:
    alertDefinition:
         conditions: [org.rhq.core.domain.alert.builder.condition.AbsoluteValueCondition@357d477b]
         resourceId: 11293

rhqadmin@localhost:7080$

Notice that TimeUnits and Category are auto-completed incorrectly (see BZ 1155096). The correct syntax includes AlertDampening in the beginning of those enums.

Setting recovery settings

There are two options on the AlertDefinitionTemplate, "disableWhenFired (boolean)" and "recoverAlert (Integer)"

Adding conditions

Conditions are added by creating a new object that extends AbstractCondition and then using the addCondition(AbstractCondition) function on the AlertDefinitionTemplate. The list of available conditions is:

Class name

Corresponding GUI term

AbsoluteValueCondition

Measurement Absolute Value Threshold

AvailabilityCondition

Availability Change

AvailabilityDurationCondition

Availability Duration

BaselineCondition

Measurement Baseline Threshold

ChangesCondition

Measurement Value Change

ControlCondition

Operation Execution

DriftCondition

Drift Detection

EventCondition

Event Detection

RangeCondition

Measurement Value Range

ResourceConfigurationCondition

Resource Configuration Change

TraitCondition

Trait Value Change

Example of adding new AbsoluteValue condition (with tabulator auto-complete showing the options):

rhqadmin@localhost:7080$ valueCondition.

alertCondition            comparator                measurementDefinitionId   metric                    value
rhqadmin@localhost:7080$ valueCondition.comparator(AlertConditionOperator.

AlertConditionOperator.AVAIL_DURATION_DOWN        AlertConditionOperator.AVAIL_DURATION_NOT_UP      AlertConditionOperator.AVAIL_GOES_DISABLED
AlertConditionOperator.AVAIL_GOES_DOWN            AlertConditionOperator.AVAIL_GOES_NOT_UP          AlertConditionOperator.AVAIL_GOES_UNKNOWN
AlertConditionOperator.AVAIL_GOES_UP              AlertConditionOperator.CHANGES                    AlertConditionOperator.CHANGES_FROM
AlertConditionOperator.CHANGES_TO                 AlertConditionOperator.EQUALS                     AlertConditionOperator.GREATER_THAN
AlertConditionOperator.GREATER_THAN_OR_EQUAL_TO   AlertConditionOperator.LESS_THAN                  AlertConditionOperator.LESS_THAN_OR_EQUAL_TO
AlertConditionOperator.REGEX
rhqadmin@localhost:7080$ valueCondition.comparator(AlertConditionOperator.LESS_THAN)
AbsoluteValueCondition:
	         alertCondition: org.rhq.core.domain.alert.AlertCondition[ id=0, category=Measurement Threshold, name=null, comparator='<', threshold=null, option=null ]
	measurementDefinitionId: 0

rhqadmin@localhost:7080$ valueCondition.metric(11641)
AbsoluteValueCondition:
	         alertCondition: org.rhq.core.domain.alert.AlertCondition[ id=0, category=Measurement Threshold, name=null, comparator='<', threshold=null, option=null ]
	measurementDefinitionId: 11641

rhqadmin@localhost:7080$ valueCondition.value(90)
AbsoluteValueCondition:
	         alertCondition: org.rhq.core.domain.alert.AlertCondition[ id=0, category=Measurement Threshold, name=null, comparator='<', threshold=90.0, option=null ]
	measurementDefinitionId: 11641

rhqadmin@localhost:7080$ emptyAlertDef.addCondition(valueCondition)
AlertDefinitionTemplate:
	alertDefinition: org.rhq.core.domain.alert.AlertDefinition[ id=0, name=empty alertDefinition, conditionExpression=ANY, priority=Medium,  ]
	     conditions: [org.rhq.core.domain.alert.builder.condition.AbsoluteValueCondition@357d477b]
	     resourceId: 11293

rhqadmin@localhost:7080$

Notification options

Creating notification with the generic API:

rhqadmin@localhost:7080$ var conf = new Configuration()

rhqadmin@localhost:7080$ conf.

addRawConfiguration        afterUnmarshal             allProperties              builder                    cleanoutRawConfiguration   clone
createdTime                deepCopy                   deepCopyWithoutProxies     emptyIterator              get                        getList
getMap                     getSimple                  getSimpleValue             id                         listProperties             map
mapProperties              modifiedTime               names                      notes                      properties                 put
rawConfigurations          remove                     removeRawConfiguration     resize                     setSimpleValue             simpleProperties
toString                   version
rhqadmin@localhost:7080$ conf.setSimpleValue("subjectId", "rhqadmin")

rhqadmin@localhost:7080$ var notification = new AlertNotificationTemplate()

rhqadmin@localhost:7080$ notification.

alertNotification    configuration        extraConfiguration   sender
rhqadmin@localhost:7080$ notification.configuration(conf)
AlertNotificationTemplate:
	alertNotification: AlertNotification{id=0, senderName='null'}

rhqadmin@localhost:7080$ notification.sender("SubjectsSender")
AlertNotificationTemplate:
	alertNotification: AlertNotification{id=0, senderName='SubjectsSender'}

rhqadmin@localhost:7080$ emptyAlertDef.addNotification(notification)
AlertDefinitionTemplate:
	alertDefinition: org.rhq.core.domain.alert.AlertDefinition[ id=0, name=empty alertDef, conditionExpression=ANY, priority=Medium,  ]
	     conditions: []
	     resourceId: 10001

rhqadmin@localhost:7080$

There are also pre-defined assist methods for included alert sender plugins:

Class name

Equivalent senderPlugin

SystemUserNotifier

Alert:Subject

EmailNotifier

Alert:Email

CliNotifier

Alert:CLI

SnmpNotifier

 Alert:SNMP
 

An example to use SystemUserNotifier:

rhqadmin@localhost:7080$ var subjectNotification = new SystemUserNotifier()

rhqadmin@localhost:7080$ subjectNotification.addRecipient("rhqadmin")
SystemUserNotifier:
	alertNotification: AlertNotification{id=0, senderName='SubjectsSender'}

rhqadmin@localhost:7080$ emptyAlertDef.add

addCondition      addNotification
rhqadmin@localhost:7080$ emptyAlertDef.addNotification(subjectNotification)
AlertDefinitionTemplate:
	alertDefinition: org.rhq.core.domain.alert.AlertDefinition[ id=0, name=empty alertDef, conditionExpression=ANY, priority=Medium,  ]
	     conditions: []
	     resourceId: 10001

rhqadmin@localhost:7080$
JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-11 13:31:46 UTC, last content change 2014-10-31 13:08:33 UTC.